package com.easyprogram.article.controller;

import com.easyprogram.entity.Result;
import com.easyprogram.entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class BaseExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handler(Exception e){
        System.out.println("处理异常");

//        if(e instanceof NullPointerException){
//            //处理异常的方法
//        }else if(e instanceof ArithmeticException){
//            //处理异常的方法
//        }

        Result result = new Result(false, StatusCode.ERROR, e.getMessage());
        return result;
    }
}
